package com.example.demo_mvp.base.view;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.demo_mvp.base.presenter.BasePresenter;

/**
 * @author yaotianxue
 * @description
 * @date 2025/1/9
 */
public abstract class BaseActivity<V,P extends BasePresenter<V>> extends AppCompatActivity implements IBaseView {
    protected  P mPresenter;
    //初始化数据：创建mPresenter
    protected abstract void initData();
    //初始化
    protected abstract void initView(Bundle savedInstanceState);
    //布局id
    protected abstract int bindLayout();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(bindLayout());
        initView(savedInstanceState);
        initData();
        //使用弱应用绑定view
        if(mPresenter != null){
            mPresenter.attachView((V)this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //解绑view
        if(mPresenter != null){
            mPresenter.detachView();
        }
    }

    @Override
    public void onLoading() {
        Toast.makeText(this, "数据加载中", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onLoadSuccess() {
        Toast.makeText(this, "数据加载成功", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onLoadFailed() {
        Toast.makeText(this, "数据加载失败", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onEmpty() {
        Toast.makeText(this, "空数据", Toast.LENGTH_SHORT).show();
    }
}
